<?php require_once('../Connections/morroco.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE asignatura SET descripcion=%s, id_usuario=%s WHERE ID=%s",
                       GetSQLValueString($_POST['descripcion'], "text"),
                       GetSQLValueString($_POST['id_usuario'], "int"),
                       GetSQLValueString($_POST['ID'], "int"));

  mysql_select_db($database_morroco, $morroco);
  $Result1 = mysql_query($updateSQL, $morroco) or die(mysql_error());

  $updateGoTo = "../menu.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_asignatura = "-1";
if (isset($_GET['asignatura'])) {
  $colname_asignatura = $_GET['asignatura'];
}
mysql_select_db($database_morroco, $morroco);
$query_asignatura = sprintf("SELECT * FROM asignatura WHERE ID = %s", GetSQLValueString($colname_asignatura, "int"));
$asignatura = mysql_query($query_asignatura, $morroco) or die(mysql_error());
$row_asignatura = mysql_fetch_assoc($asignatura);
$totalRows_asignatura = mysql_num_rows($asignatura);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/principal2.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<link rel="icon" type="image/x-icon" href="../imagenes/favicon.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Edición de Asignatura</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="../css/twoColFixLtHdr.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.container .header h1 strong {
	color: #FFF;
}
</style>
</head>

<body>

<div class="container">
  <div class="header">
    <h1>Generador de Horarios</h1>
  <!-- end .header --></div>
  <div class="sidebar1">
    <ul class="nav">
      <li><a href="../menu.php">Inicio / Menú</a></li>
    </ul>
    <p><img src="../imagenes/morroco.png" width="149" height="94" alt="morroco" /></p>
    <!-- end .sidebar1 --></div>
  <div class="content"> <!-- InstanceBeginEditable name="EditRegion3" -->
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="center" valign="middle"><strong>Editar Asignatura</strong></td>
      </tr>
    </table>
    <br />
    <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
      <table width="100%" align="center">
        <tr valign="baseline">
          <td width="20%" align="right" nowrap="nowrap">ID:</td>
          <td><input style="text-align:center" readonly="readonly" disabled="disabled" type="text" name="ID" value="<?php echo $row_asignatura['ID']; ?>" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td width="20%" align="right" nowrap="nowrap">Descripcion:</td>
          <td><input style="text-align:center" required="required" type="text" name="descripcion" value="<?php echo htmlentities($row_asignatura['descripcion'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td width="20%" align="right" nowrap="nowrap">&nbsp;</td>
          <td><input type="submit" value="Guardar" />
          <input name="regresar" type="button" id="regresar" onclick="window.location.href='../menu.php'" value="Regresar" /></td>
        </tr>
      </table>
      <input type="hidden" name="id_usuario" value="<?php echo htmlentities($row_asignatura['id_usuario'], ENT_COMPAT, 'utf-8'); ?>" />
      <input type="hidden" name="MM_update" value="form1" />
      <input type="hidden" name="ID" value="<?php echo $row_asignatura['ID']; ?>" />
    </form>
    <p>&nbsp;</p>
<br />
    <!-- InstanceEndEditable -->    <!-- end .content --></div>
  <div class="footer">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="middle"><a href="http://www.ch0ngu1.com" target="new">www.Ch0nGu1.com</a></td>
  </tr>
</table>
    <!-- end .footer --></div>
  <!-- end .container --></div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($asignatura);
?>
